/*
 * Exploder
 * 
 * Tero Pyylampi (218437), Jussi Tuurinkoski (211594)
 *
 * A collection of static functions available for LUA interface
 */

#include "GameLevelEngine.h"
#include "../GameEngine.h"
#include "../GameScene.h"
#include "../GameCamera.h"
#include "../layers/LayerGame.h"
#include "../objects/physicobjects/GamePhysicObjectEngine.h"
#include "../../LuaInterface.h"
#include "../../Resources.h"
#include "../../Common.h"

GameEngine *GameLevelEngine::mGameEngine = 0;
GameCamera *GameLevelEngine::mGameCamera = 0;

// default constructor
GameLevelEngine::GameLevelEngine( LuaInterface *luaInterface, GameEngine *gameEngine, GameCamera *gameCamera ) :
	mLuaInterface( luaInterface ) {
	mGameEngine = gameEngine;
	mGameCamera = gameCamera;
}

// default destructor
GameLevelEngine::~GameLevelEngine() {}

// start level
void GameLevelEngine::startLevel( char *level ) {
	mLuaInterface->executeScript( getResource( level ) );
	mLuaInterface->callInitFunction();
}

// update this engine
void GameLevelEngine::update( cocos2d::ccTime dt ) {
	mLuaInterface->callUpdateFunction( dt );
}

// create a construction element to the level
void GameLevelEngine::createConstructionElement( ElementType itemProperties, float worldX, float worldY, float rotation, PhysicObjectItems itemMainType ) {
	mGameEngine->getPhysicObjectEngine()->createElementObject( mGameEngine->getGameWorld(), mGameEngine->getGameLayer(), mGameCamera, false, itemMainType, b2Vec2( worldX, worldY ), rotation, itemProperties );
}
